package com.zk.algorithm.dynamicprogramming;

import com.zk.algorithm.annotation.LeetCodeExplore;

/**
 * 不限制次数
 *
 * day2 买，day3 卖；day4 买，day5 卖
 *
 * @author zk
 */
@LeetCodeExplore
public class BestTimeToBuyAndSellStock2 {

    /**
     * 可以无限制操作
     *
     * [7,1,5,3,6,4]
     * [1,2,3,4,5]
     * [7,6,4,3,1]
     *
     * @param prices
     * @return
     */
    public int maxProfit(int[] prices) {
        int total = 0;

        for (int i = 0; i < prices.length - 1; i++) {
            if (prices[i + 1] > prices[i])
                total += prices[i + 1] - prices[i];
        }

        return total;
    }

}
